/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func buildTree(inorder []int, postorder []int) *TreeNode {
    if len(inorder)<1 || len(postorder) < 1 {
        return nil
    }
    // 找到后续遍历数组最后一个值，用于切割数组
    ndoeValue := postorder[len(postorder)-1]
    index := findIndex(inorder, ndoeValue)
    // 迭代构造树
    root := &TreeNode{
        Val: ndoeValue,
        Left: buildTree(inorder[:index], postorder[:index]),
        Right: buildTree(inorder[index+1:], postorder[index:len(postorder)-1]),
    }
    return root
}

func findIndex(inorder []int, target int) int {
    for i, v := range inorder {
        if v == target {
            return i
        }
    }
    return -1
}